package com.cskaoyan.controller.wxcontroller;

import com.cskaoyan.bean.data.WxBaseData2;
import com.cskaoyan.bean.param.WxCommentListBO;
import com.cskaoyan.bean.pojo.GoodsComment;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.wxvo.WxCommentCountVO;
import com.cskaoyan.bean.wxvo.WxCommentListVO;
import com.cskaoyan.service.WxCommentService;
import com.cskaoyan.utils.wx.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/comment")
public class WxCommentController {

    @Autowired
    WxCommentService wxCommentService;

    @RequestMapping("list")
    public BaseRespVo wxCommentList(WxCommentListBO wxCommentListBO) {
        WxBaseData2<WxCommentListVO> wxCommentListVO = wxCommentService.queryCommentList(wxCommentListBO);
        return BaseRespVo.ok(wxCommentListVO);
    }

    @RequestMapping("count")
    public BaseRespVo wxCommentCount(Integer valueId, Integer type) {
        WxCommentCountVO wxCommentCountVO = wxCommentService.countComment(valueId, type);
        return BaseRespVo.ok(wxCommentCountVO);
    }
    @RequestMapping("post")
    public BaseRespVo wxCommentPost(@RequestBody GoodsComment goodsComment){
        Integer userId = UserUtil.getUserId();
        GoodsComment goodsComment1=wxCommentService.postComment(goodsComment,userId);
        if(goodsComment1!=null){
            return BaseRespVo.ok(goodsComment1);
        }
        return BaseRespVo.fail();
    }




}